package com.cskaoyan.service;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.goodsbean.wxbean.*;
import com.cskaoyan.bean.goodsbean.wxvo.*;
import com.cskaoyan.mapper.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.security.auth.Subject;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;

/**
 * @program: whyccz-mall-project
 * @description:
 * @create: 2021-06-07 14:50
 **/
@Service
public class WXGoodsServiceImpl implements WXGoodService {
	@Autowired
	GoodsMapper goodsMapper;
	@Autowired
	CategoryMapper categoryMapper;
	@Autowired
	AdMapper adMapper;
	@Autowired
	BrandMapper brandMapper;
	@Autowired
	CouponMapper couponMapper;
	@Autowired
	CouponUserMapper couponUserMapper;
	@Autowired
	TopicMapper topicMapper;
	@Autowired
	SearchHistoryMapper searchHistoryMapper;
	@Autowired
	CollectMapper collectMapper;
	@Autowired
	GoodsAttributeMapper attributeMapper;
	@Autowired
	GoodsProductMapper productMapper;
	@Autowired
	GoodsSpecificationMapper specificationMapper;
	@Autowired
	IssueMapper issueMapper;
	@Autowired
	CommentMapper commentMapper;
	@Autowired
	UserMapper userMapper;
	@Autowired
	FootPrintMapper footPrintMapper;


	@Override
	public HomeIndexVO getHomeIndex() {
		HomeIndexVO homeIndexVO = new HomeIndexVO();
		//newGoodsList goods按新品 六个
		String sortTime = "add_time";
		String order = "desc";
		String sortId = "id";
		String orderAsc = "asc";
		GoodsExample goodsExampleForNewGoods = new GoodsExample();
		goodsExampleForNewGoods.setOrderByClause(sortTime + " " + order);
		GoodsExample.Criteria criteriaForNewGoods = goodsExampleForNewGoods.createCriteria();
		criteriaForNewGoods.andIsNewEqualTo(true);
		criteriaForNewGoods.andIsOnSaleEqualTo(true);
		criteriaForNewGoods.andDeletedEqualTo(false);
		List<Goods> goodsNew = goodsMapper.selectByExample(goodsExampleForNewGoods);
		int limit = 6;
		List<NewGoodsListBean> newGoodsListBeanList = new ArrayList<>();
		for (Goods good : goodsNew) {
			if (limit > 0) {
				NewGoodsListBean newGoodsListBean = new NewGoodsListBean();
				newGoodsListBean.setId(good.getId());
				newGoodsListBean.setName(good.getName());
				newGoodsListBean.setBrief(good.getBrief());
				newGoodsListBean.setPicUrl(good.getPicUrl());
				newGoodsListBean.setIsNew(good.getIsNew());
				newGoodsListBean.setIsHot(good.getIsHot());
				newGoodsListBean.setCounterPrice(good.getCounterPrice().intValue());
				newGoodsListBean.setRetailPrice(good.getRetailPrice().intValue());
				newGoodsListBeanList.add(newGoodsListBean);
				limit--;
			} else break;
		}
		homeIndexVO.setNewGoodsList(newGoodsListBeanList);


		//couponList 优惠券推荐 首先是时间倒序 然后是领取过的不显示  timeType不为0的(之后加)  未删除的显示
		CouponExample couponExample = new CouponExample();
		couponExample.setOrderByClause(sortTime + " " + order);
		couponExample.or();
		Integer couponLimit = 3;
		CouponExample.Criteria couponExampleCriteria = couponExample.createCriteria();
		couponExampleCriteria.andDeletedEqualTo(false);//timetype为0的优惠券
//.andTimeTypeEqualTo((short) 0)
//				.andStartTimeLessThanOrEqualTo(new Date())
//				.andEndTimeGreaterThanOrEqualTo(new Date());

//		couponExample.or(couponExampleCriteria);
		List<Coupon> coupons = couponMapper.selectByExample(couponExample);
		CouponUserExample couponUserExample = new CouponUserExample();
		List<CouponUser> couponUsers = couponUserMapper.selectByExample(couponUserExample);
		List<Integer> userCoupons = new ArrayList<>();
		HashMap<Integer, Boolean> couponMap = new HashMap<>();
		for (CouponUser couponUser : couponUsers) {
			Integer id = couponUser.getId();
			userCoupons.add(id);
			couponMap.put(id, false);
		}


		List<CouponListBean> couponListBeanList = new ArrayList<>();
		for (Coupon coupon : coupons) {
			if (couponLimit > 0) {
				if (couponMap.containsKey(coupon.getId())) {
					continue;//已领取该优惠券 跳过
				}
				CouponListBean couponListBean = new CouponListBean();
				couponListBean.setDays(coupon.getDays());
				couponListBean.setDesc(coupon.getDesc());
				couponListBean.setDiscount(coupon.getDiscount().intValue());
				couponListBean.setMin(coupon.getMin().intValue());
				couponListBean.setId(coupon.getId());
				couponListBean.setName(coupon.getName());
				couponListBean.setTag(coupon.getTag());
				if (coupon.getStartTime()!=null) {
					SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					couponListBean.setStartTime(simpleDateFormat.format(coupon.getStartTime()));
					couponListBean.setEndTime(simpleDateFormat.format(coupon.getEndTime()));
				}
				couponListBeanList.add(couponListBean);
				couponLimit--;
			} else break;
		}
		homeIndexVO.setCouponList(couponListBeanList);

		//channel 一级类目

		CategoryExample categoryExample = new CategoryExample();
		categoryExample.setOrderByClause(sortId + " " + orderAsc);
		CategoryExample.Criteria categoryExampleCriteria = categoryExample.createCriteria();
		categoryExampleCriteria.andPidEqualTo(0);
		categoryExampleCriteria.andDeletedEqualTo(false);
		List<Category> categories = categoryMapper.selectByExample(categoryExample);
		List<ChannelBean> channelBeanList = new ArrayList<>();
		for (Category category : categories) {
			ChannelBean channelBean = new ChannelBean();
			channelBean.setId(category.getId());
			channelBean.setName(category.getName());
			channelBean.setIconUrl(category.getIconUrl());
			channelBeanList.add(channelBean);
		}
		homeIndexVO.setChannel(channelBeanList);


		//grouponList  团购推荐


		//banner 广告
		AdExample adExample = new AdExample();
		adExample.setOrderByClause(sortId + " " + orderAsc);//按id增序
		AdExample.Criteria adExampleCriteria = adExample.createCriteria();
		adExampleCriteria.andPositionEqualTo((byte) 1);
		adExampleCriteria.andEnabledEqualTo(true);
		adExampleCriteria.andDeletedEqualTo(false);
		List<Ad> ads = adMapper.selectByExample(adExample);
		List<BannerBean> bannerBeanList = new ArrayList<>();
		for (Ad ad : ads) {

			BannerBean bannerBean = new BannerBean();
			bannerBean.setId(ad.getId());
			bannerBean.setName(ad.getName());
			bannerBean.setLink(ad.getLink());
			bannerBean.setUrl(ad.getUrl());
			bannerBean.setPosition((int) ad.getPosition());
			bannerBean.setContent(ad.getContent());
			bannerBean.setEnabled(ad.getEnabled());
			bannerBean.setAddTime(ad.getAddTime().toString());//为什么用addtime  不应该用starttime么
			bannerBean.setUpdateTime(ad.getUpdateTime().toString());
			bannerBean.setDeleted(ad.getDeleted());
			bannerBeanList.add(bannerBean);
		}
		homeIndexVO.setBanner(bannerBeanList);
		//brandList 品牌推荐 limit 4
		BrandExample brandExample = new BrandExample();
		brandExample.setOrderByClause(sortTime + " " + order);
		brandExample.createCriteria().andDeletedEqualTo(false);
		List<Brand> brands = brandMapper.selectByExample(brandExample);
		int brandLimit = 4;
		List<BrandListBean> brandListBeanList = new ArrayList<>();
		for (Brand brand : brands) {
			if (brandLimit > 0) {
				BrandListBean brandListBean = new BrandListBean();
				brandListBean.setId(brand.getId());
				brandListBean.setDesc(brand.getDesc());
				brandListBean.setFloorPrice(brand.getFloorPrice().intValue());
				brandListBean.setName(brand.getName());
				brandListBean.setPicUrl(brand.getPicUrl());
				brandListBeanList.add(brandListBean);
				brandLimit--;
			} else break;
		}
		homeIndexVO.setBrandList(brandListBeanList);


		//hotGoodsList 人气推荐 六个
		GoodsExample goodsExampleForHotGoods = new GoodsExample();
		goodsExampleForHotGoods.setOrderByClause(sortTime + " " + order);
		GoodsExample.Criteria criteriaForHotGoods = goodsExampleForHotGoods.createCriteria();
		criteriaForHotGoods.andIsHotEqualTo(true);
		criteriaForHotGoods.andIsOnSaleEqualTo(true);
		criteriaForHotGoods.andDeletedEqualTo(false);
		List<Goods> goodsHot = goodsMapper.selectByExample(goodsExampleForNewGoods);
		int limitHot = 6;
		List<HotGoodsListBean> hotGoodsListBeanList = new ArrayList<>();
		for (Goods good : goodsHot) {
			if (limitHot > 0) {
				HotGoodsListBean hotGoodsListBean = new HotGoodsListBean();
				hotGoodsListBean.setId(good.getId());
				hotGoodsListBean.setName(good.getName());
				hotGoodsListBean.setBrief(good.getBrief());
				hotGoodsListBean.setPicUrl(good.getPicUrl());
				hotGoodsListBean.setIsNew(good.getIsNew());
				hotGoodsListBean.setIsHot(good.getIsHot());
				hotGoodsListBean.setCounterPrice(good.getCounterPrice().intValue());
				hotGoodsListBean.setRetailPrice(good.getRetailPrice().intValue());
				hotGoodsListBeanList.add(hotGoodsListBean);
				limitHot--;
			} else break;
		}
		homeIndexVO.setHotGoodsList(hotGoodsListBeanList);
		//topicList 专题精选
		TopicExample topicExample = new TopicExample();
		topicExample.setOrderByClause(sortTime + " " + order);
		List<Topic> topics = topicMapper.selectByExample(topicExample);
		List<TopicListBean> topicListBeanList = new ArrayList<>();
		for (Topic topic : topics) {
			TopicListBean topicListBean = new TopicListBean();
			topicListBean.setId(topic.getId());
			topicListBean.setTitle(topic.getTitle());
			topicListBean.setSubtitle(topic.getSubtitle());
			topicListBean.setPrice(topic.getPrice().intValue());
			topicListBean.setReadCount(topic.getReadCount());
			topicListBean.setPicUrl(topic.getPicUrl());
			topicListBeanList.add(topicListBean);
		}
		homeIndexVO.setTopicList(topicListBeanList);

		//floorGoodsList 底部商品类 按一级类目分
		CategoryExample categoryExampleSub = new CategoryExample();
		Integer catGoodsLimit = 4;
		CategoryExample.Criteria categoryExampleCriteriaSub = categoryExampleSub.createCriteria();
		categoryExampleCriteriaSub.andPidNotEqualTo(0);
		categoryExampleCriteriaSub.andDeletedEqualTo(false);
		List<Category> categoriesSub = categoryMapper.selectByExample(categoryExampleSub);//二级目录
		HashMap<Integer, Integer> categoryMap = new HashMap<>();

		GoodsExample goodsExample = new GoodsExample();
		List<Goods> goods = goodsMapper.selectByExample(goodsExample);//所有商品

		//一级目录对应所有的商品
		List<FloorGoodsListBean> floorGoodsListBeanList = new ArrayList<>();
		//把一级目录都写在map 对二级目录进行遍历
		for (Category category : categories) {
			FloorGoodsListBean floorGoodsListBean = new FloorGoodsListBean();
			floorGoodsListBean.setId(category.getId());
			floorGoodsListBean.setName(category.getName());
			List<GoodsBean> goodsList = new ArrayList<>();
			for (Category categorySub : categoriesSub) {
				if (categorySub.getPid().equals(category.getId())) {
					for (Goods good : goods) {
						if (good.getCategoryId().equals(categorySub.getId())) {
//							goodsList.add(good);
							GoodsBean goodsBean = new GoodsBean();
							goodsBean.setId(good.getId());
							goodsBean.setBrief(good.getBrief());
							goodsBean.setName(good.getName());
							goodsBean.setPicUrl(good.getPicUrl());
							goodsBean.setCounterPrice(good.getCounterPrice().intValue());
							goodsBean.setRetailPrice(good.getRetailPrice().intValue());
							goodsList.add(goodsBean);
							if (goodsList.size() >= catGoodsLimit) break;
						}
					}
					if (goodsList.size() >= catGoodsLimit) break;
				}
			}

			floorGoodsListBean.setGoodsList(goodsList);
			floorGoodsListBeanList.add(floorGoodsListBean);

		}
		homeIndexVO.setFloorGoodsList(floorGoodsListBeanList);
		return homeIndexVO;
	}

	@Override
	public GoodsCountVO getGoodsCount() {
		GoodsExample goodsExample = new GoodsExample();
		goodsExample.createCriteria().andDeletedEqualTo(false);
		List<Goods> goods = goodsMapper.selectByExample(goodsExample);
		Integer count = 0;
		for (Goods good : goods) {
			count++;
		}
		GoodsCountVO goodsCountVO = new GoodsCountVO();
		goodsCountVO.setGoodsCount(count);
		return goodsCountVO;
	}

	@Override
	public GoodsCategoryVO getGoodsCategory(Integer id) {
		CategoryExample categoryExample1 = new CategoryExample();
		CategoryExample categoryExample2 = new CategoryExample();
		CategoryExample categoryExample3 = new CategoryExample();
		CategoryExample.Criteria criteria1 = categoryExample1.createCriteria();
		CategoryExample.Criteria criteria2 = categoryExample2.createCriteria();
		CategoryExample.Criteria criteria3 = categoryExample3.createCriteria();
		criteria1.andDeletedEqualTo(false).andIdEqualTo(id);
		List<Category> categories = categoryMapper.selectByExample(categoryExample1);
		GoodsCategoryVO goodsCategoryVO = new GoodsCategoryVO();
		Category currentCategory = categories.get(0);//当前目录  判断是一级目录还是二级目录
		if (currentCategory.getPid()!=0) {//是二级目录
			criteria2.andIdEqualTo(currentCategory.getPid()).andDeletedEqualTo(false);//根据pid搜索父目录
			criteria3.andPidEqualTo(currentCategory.getPid()).andDeletedEqualTo(false);//根据pid搜索兄弟目录

			List<Category> categories2 = categoryMapper.selectByExample(categoryExample2);//父目录
			List<Category> categories3 = categoryMapper.selectByExample(categoryExample3);//兄弟目录


			goodsCategoryVO.setCurrentCategory(currentCategory);
			goodsCategoryVO.setParentCategory(categories2.get(0));
			goodsCategoryVO.setBrotherCategory(categories3);
		}else {//一级目录
			criteria2.andPidEqualTo(currentCategory.getId()).andDeletedEqualTo(false);
			List<Category> categories2 = categoryMapper.selectByExample(categoryExample2);//兄弟目录
			goodsCategoryVO.setCurrentCategory(categories2.get(0));
			goodsCategoryVO.setParentCategory(currentCategory);
			goodsCategoryVO.setBrotherCategory(categories2);

		}
		return goodsCategoryVO;
	}

	@Override
	public GoodsListVO getGoodsList(GoodsListReq goodsListReq) {
		GoodsListVO goodsListVO = new GoodsListVO();
		PageHelper.startPage(goodsListReq.getPage(),goodsListReq.getSize());//分页限制
		GoodsExample goodsExample = new GoodsExample();
		//对goodsList校验 判断是按keyword还是类型搜索
		if (goodsListReq.getKeyword()!=null){//按keyword 模糊查询
			goodsExample.setOrderByClause(goodsListReq.getSort()+" "+goodsListReq.getOrder());
			GoodsExample.Criteria criteria = goodsExample.createCriteria();
			criteria.andDeletedEqualTo(false).andNameLike("%"+goodsListReq.getKeyword()+"%");
			//如果登录了 把keyword放进搜索历史
			org.apache.shiro.subject.Subject subject = SecurityUtils.getSubject();
			Object principal = subject.getPrincipal();
			if(principal!=null){
				User user = (User)principal;
				SearchHistory searchHistory = new SearchHistory();
				searchHistory.setDeleted(false);
				searchHistory.setKeyword(goodsListReq.getKeyword());
				searchHistory.setFrom("pc");
				searchHistory.setAddTime(LocalDateTime.now());
				searchHistory.setUpdateTime(LocalDateTime.now());
				searchHistory.setUserId(user.getId());
				searchHistoryMapper.insertSelective(searchHistory);
			}


		}else if (goodsListReq.getCategoryId()!=null){//按二级目录
			GoodsExample.Criteria criteria = goodsExample.createCriteria();
			criteria.andDeletedEqualTo(false).andCategoryIdEqualTo(goodsListReq.getCategoryId());

		}else if (goodsListReq.getCategoryId()!=null){//按制造商
			GoodsExample.Criteria criteria = goodsExample.createCriteria();
			criteria.andDeletedEqualTo(false).andBrandIdEqualTo(goodsListReq.getCategoryId());

		}
		List<Goods> goods = goodsMapper.selectByExample(goodsExample);
		List<GoodsBean> goodsBeanList=new ArrayList<>();
		for (Goods good : goods) {
			GoodsBean goodsBean = new GoodsBean();
			goodsBean.setId(good.getId());
			goodsBean.setName(good.getName());
			goodsBean.setBrief(good.getBrief());
			goodsBean.setPicUrl(good.getPicUrl());
			goodsBean.setRetailPrice(good.getRetailPrice().intValue());
			goodsBean.setCounterPrice(good.getCounterPrice().intValue());
			goodsBeanList.add(goodsBean);
		}
		PageInfo<Goods> goodsPageInfo = new PageInfo<>(goods);
		long total = goodsPageInfo.getTotal();

		goodsListVO.setCount(total);
		goodsListVO.setGoodsList(goodsBeanList);
		return goodsListVO;
	}

	@Override
	public WXGoodsDetailVO getGoodsDetail(Integer id) {
		WXGoodsDetailVO wxGoodsDetailVO = new WXGoodsDetailVO();
		//是否收藏 TODO 用户id 专题评论
		org.apache.shiro.subject.Subject subject = SecurityUtils.getSubject();
		Object principal = subject.getPrincipal();
		if (principal!=null){
			User user= (User) principal;
			CollectExample collectExample = new CollectExample();
			CollectExample.Criteria criteria = collectExample.createCriteria();
			criteria.andDeletedEqualTo(false).andUserIdEqualTo(user.getId()).andTypeEqualTo((byte)0)
					.andValueIdEqualTo(id);
			List<Collect> collects = collectMapper.selectByExample(collectExample);
			if (collects!=null){
				wxGoodsDetailVO.setUserHasCollect(1);
			}else {
				wxGoodsDetailVO.setUserHasCollect(0);
			}
			//添加足迹
			FootPrint footPrint = new FootPrint();
			footPrint.setUserId(user.getId());
			footPrint.setGoodsId(id);
			footPrint.setDeleted(false);
			footPrint.setAddTime(new Date());
			footPrint.setUpdateTime(new Date());
			footPrintMapper.insertSelective(footPrint);
		}


		GoodsExample goodsExample = new GoodsExample();
		GoodsExample.Criteria criteria1 = goodsExample.createCriteria();
		criteria1.andDeletedEqualTo(false).andIdEqualTo(id);



		List<Goods> goods = goodsMapper.selectByExampleWithBLOBs(goodsExample);

		Goods goods1 = goods.get(0);
		wxGoodsDetailVO.setInfo(goods1);

		//products
		GoodsProductExample productExample = new GoodsProductExample();
		GoodsProductExample.Criteria criteria2 = productExample.createCriteria();
		criteria2.andGoodsIdEqualTo(id).andDeletedEqualTo(false);
		List<GoodsProduct> goodsProducts = productMapper.selectByExample(productExample);
		wxGoodsDetailVO.setProductList(goodsProducts);

		//specs
		GoodsSpecificationExample specificationExample = new GoodsSpecificationExample();
		GoodsSpecificationExample.Criteria criteria3 = specificationExample.createCriteria();
		criteria3.andGoodsIdEqualTo(id).andDeletedEqualTo(false);
		List<GoodsSpecification> goodsSpecifications = specificationMapper.selectByExample(specificationExample);
		List<SpecVO> specVOList=new ArrayList<>();
		HashMap<GoodsSpecification, String> specHashMap = new HashMap<>();
		for (GoodsSpecification goodsSpecification : goodsSpecifications) {
			specHashMap.put(goodsSpecification,goodsSpecification.getSpecification());

		}
		Collection<String> values = specHashMap.values();
		for (String value : values) {
			SpecVO specVO = new SpecVO();
			List<GoodsSpecification> goodsSpecificationList=new ArrayList<>();
			for (Map.Entry<GoodsSpecification, String> goodsSpecificationStringEntry : specHashMap.entrySet()) {
				if (	goodsSpecificationStringEntry.getValue().equals(value)){
					goodsSpecificationList.add(goodsSpecificationStringEntry.getKey());
				}
			}
			specVO.setName(value);
			specVO.setValueList(goodsSpecificationList);
			specVOList.add(specVO);
		}
		wxGoodsDetailVO.setSpecificationList(specVOList);

		//attribute
		GoodsAttributeExample attributeExample = new GoodsAttributeExample();
		GoodsAttributeExample.Criteria criteria4 = attributeExample.createCriteria();
		criteria4.andGoodsIdEqualTo(id).andDeletedEqualTo(false);
		List<GoodsAttribute> goodsAttributes = attributeMapper.selectByExample(attributeExample);
		wxGoodsDetailVO.setAttribute(goodsAttributes);

		BrandExample brandExample = new BrandExample();
		BrandExample.Criteria criteria5 = brandExample.createCriteria();
		criteria5.andIdEqualTo(goods1.getBrandId()).andDeletedEqualTo(false);
		List<Brand> brands = brandMapper.selectByExample(brandExample);
		if (brands.size()!=0)wxGoodsDetailVO.setBrand(brands.get(0));


		IssueExample issueExample = new IssueExample();
		IssueExample.Criteria criteria6 = issueExample.createCriteria();
		criteria6.andDeletedEqualTo(false);
		List<Issue> issues = issueMapper.selectByExample(issueExample);
		wxGoodsDetailVO.setIssue(issues);
		//TODO 用户信息 和专题评论
		CommentExample commentExample = new CommentExample();
		CommentExample.Criteria criteria7 = commentExample.createCriteria();
		criteria7.andDeletedEqualTo(false)
				.andTypeEqualTo((byte)0).andValueIdEqualTo(goods1.getId());
		List<Comment> comments = commentMapper.selectByExample(commentExample);
		List<GoodsDeatailCommentVO> goodsDeatailCommentVOList=new ArrayList<>();
		//获取用户昵称 和 头像
		CommentBean commentBean = new CommentBean();
		int count=0;
		UserExample userExample = new UserExample();
		UserExample.Criteria criteria8 = userExample.createCriteria();
		criteria8.andDeletedEqualTo(false);
		List<User> users = userMapper.selectByExample(userExample);
		int commentLimit=2;
		for (Comment comment : comments) { //c id
			GoodsDeatailCommentVO goodsDeatailCommentVO = new GoodsDeatailCommentVO();
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			goodsDeatailCommentVO.setAddTime(simpleDateFormat.format(comment.getAddTime()));
			goodsDeatailCommentVO.setContent(comment.getContent());
			goodsDeatailCommentVO.setId(comment.getId());
			List<String> picUrls = Arrays.asList(comment.getPicUrls());
			goodsDeatailCommentVO.setPicList(picUrls);
			for (User user : users) {
				if (user.getId()==comment.getUserId()){//找到用户
					goodsDeatailCommentVO.setNickname(user.getNickname());
					goodsDeatailCommentVO.setAvatar(user.getAvatar());
				}
			}
			count++;
			if (commentLimit>0) {
				goodsDeatailCommentVOList.add(goodsDeatailCommentVO);
				commentLimit--;
			}
		}
		commentBean.setCount(count);
		commentBean.setData(goodsDeatailCommentVOList);
		wxGoodsDetailVO.setComment(commentBean);
		wxGoodsDetailVO.setShareImage("");
		wxGoodsDetailVO.setGroupon(new ArrayList<>());


		return wxGoodsDetailVO;
	}

	@Override
	public RelatedGoodsVO getRelatedGoods(Integer id) {
		//根据id找目录
		GoodsExample goodsExample = new GoodsExample();
		GoodsExample goodsExample2 = new GoodsExample();
		GoodsExample.Criteria criteria = goodsExample.createCriteria();
		GoodsExample.Criteria criteria2 = goodsExample2.createCriteria();
		criteria.andDeletedEqualTo(false).andIdEqualTo(id);
		List<Goods> goods = goodsMapper.selectByExample(goodsExample);
		Goods goods1 = goods.get(0);
		criteria2.andDeletedEqualTo(false)
				.andCategoryIdEqualTo(goods1.getCategoryId())
				.andIdNotEqualTo(id);
		List<Goods> goods2 = goodsMapper.selectByExample(goodsExample2);
		List<RelatedGoodsListBean> relatedGoodsList=new ArrayList<>();
		int limit=6;
		for (Goods good : goods2) {
			if (limit > 0) {
				RelatedGoodsListBean relatedGoodsListBean = new RelatedGoodsListBean();
				relatedGoodsListBean.setId(good.getId());
				relatedGoodsListBean.setName(good.getName());
				relatedGoodsListBean.setBrief(good.getBrief());
				relatedGoodsListBean.setIsHot(good.getIsHot());
				relatedGoodsListBean.setIsNew(good.getIsNew());
				relatedGoodsListBean.setPicUrl(good.getPicUrl());
				relatedGoodsListBean.setCounterPrice(good.getCounterPrice());
				relatedGoodsListBean.setRetailPrice(good.getRetailPrice());
				relatedGoodsList.add(relatedGoodsListBean);
				limit--;
			}else break;
		}
		RelatedGoodsVO relatedGoodsVO = new RelatedGoodsVO();
		relatedGoodsVO.setGoodsList(relatedGoodsList);
		return relatedGoodsVO;
	}


}
